package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MetallurgicalSample;
import com.ruoyi.system.service.IMetallurgicalSampleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 冶金实验室样品信息Controller
 * 
 * @author ruoyi
 * @date 2025-10-22
 */
@Controller
@RequestMapping("/system/sample")
public class MetallurgicalSampleController extends BaseController
{
    private String prefix = "system/sample";

    @Autowired
    private IMetallurgicalSampleService metallurgicalSampleService;

    @RequiresPermissions("system:sample:view")
    @GetMapping()
    public String sample()
    {
        return prefix + "/sample";
    }

    /**
     * 查询冶金实验室样品信息列表
     */
    @RequiresPermissions("system:sample:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MetallurgicalSample metallurgicalSample)
    {
        startPage();
        List<MetallurgicalSample> list = metallurgicalSampleService.selectMetallurgicalSampleList(metallurgicalSample);
        return getDataTable(list);
    }

    /**
     * 导出冶金实验室样品信息列表
     */
    @RequiresPermissions("system:sample:export")
    @Log(title = "冶金实验室样品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MetallurgicalSample metallurgicalSample)
    {
        List<MetallurgicalSample> list = metallurgicalSampleService.selectMetallurgicalSampleList(metallurgicalSample);
        ExcelUtil<MetallurgicalSample> util = new ExcelUtil<MetallurgicalSample>(MetallurgicalSample.class);
        return util.exportExcel(list, "冶金实验室样品信息数据");
    }

    /**
     * 新增冶金实验室样品信息
     */
    @RequiresPermissions("system:sample:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存冶金实验室样品信息
     */
    @RequiresPermissions("system:sample:add")
    @Log(title = "冶金实验室样品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MetallurgicalSample metallurgicalSample)
    {
        return toAjax(metallurgicalSampleService.insertMetallurgicalSample(metallurgicalSample));
    }

    /**
     * 修改冶金实验室样品信息
     */
    @RequiresPermissions("system:sample:edit")
    @GetMapping("/edit/{sampleId}")
    public String edit(@PathVariable("sampleId") Long sampleId, ModelMap mmap)
    {
        MetallurgicalSample metallurgicalSample = metallurgicalSampleService.selectMetallurgicalSampleBySampleId(sampleId);
        mmap.put("metallurgicalSample", metallurgicalSample);
        return prefix + "/edit";
    }

    /**
     * 修改保存冶金实验室样品信息
     */
    @RequiresPermissions("system:sample:edit")
    @Log(title = "冶金实验室样品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MetallurgicalSample metallurgicalSample)
    {
        return toAjax(metallurgicalSampleService.updateMetallurgicalSample(metallurgicalSample));
    }

    /**
     * 删除冶金实验室样品信息
     */
    @RequiresPermissions("system:sample:remove")
    @Log(title = "冶金实验室样品信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(metallurgicalSampleService.deleteMetallurgicalSampleBySampleIds(ids));
    }
}
